/*
 * File: Ctrl.h
 *
 * Code generated for Simulink model 'Ctrl'.
 *
 * Model version                  : 1.107
 * Simulink Coder version         : 8.2 (R2012a) 29-Dec-2011
 * TLC version                    : 8.2 (Dec 29 2011)
 * C/C++ source code generated on : Sun Apr 29 22:50:37 2012
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Texas Instruments->C2000
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTW_HEADER_Ctrl_h_
#define RTW_HEADER_Ctrl_h_
#ifndef Ctrl_COMMON_INCLUDES_
# define Ctrl_COMMON_INCLUDES_
#include <math.h>
#include <string.h>
#include "rtwtypes.h"
#endif                                 /* Ctrl_COMMON_INCLUDES_ */

#include "Ctrl_types.h"

/* Macros for accessing real-time model data structure */
#ifndef rtmGetErrorStatus
# define rtmGetErrorStatus(rtm)        ((rtm)->errorStatus)
#endif

#ifndef rtmSetErrorStatus
# define rtmSetErrorStatus(rtm, val)   ((rtm)->errorStatus = (val))
#endif

/* Block signals (auto storage) */
typedef struct {
  real32_T PWM1;                       /* '<S1>/Merge' */
  real32_T PWM2;                       /* '<S1>/Merge' */
  uint32_T AState;                     /* '<S1>/Chart' */
  uint32_T AMode;                      /* '<S1>/Chart' */
  boolean_T Kill;                      /* '<S1>/Chart' */
  boolean_T CtrlOff;                   /* '<S1>/Chart' */
  boolean_T CtrlPWM;                   /* '<S1>/Chart' */
  boolean_T CtrlOmega;                 /* '<S1>/Chart' */
  boolean_T CtrlYaw;                   /* '<S1>/Chart' */
} BlockIO_Ctrl;

/* Block states (auto storage) for system '<Root>' */
typedef struct {
  real32_T Integrator_DSTATE;          /* '<S11>/Integrator' */
  real32_T Integrator_DSTATE_j;        /* '<S9>/Integrator' */
  int32_T sfEvent;                     /* '<S1>/Chart' */
  uint32_T presentTicks;               /* '<S1>/Chart' */
  uint32_T elapsedTicks;               /* '<S1>/Chart' */
  uint32_T previousTicks;              /* '<S1>/Chart' */
  uint16_T is_active_c1_Ctrl;          /* '<S1>/Chart' */
  uint16_T is_Online;                  /* '<S1>/Chart' */
  uint16_T is_active_SystemLogic;      /* '<S1>/Chart' */
  uint16_T is_SystemLogic;             /* '<S1>/Chart' */
  uint16_T is_active_FailureDetection; /* '<S1>/Chart' */
  uint16_T is_FailureDetection;        /* '<S1>/Chart' */
  uint16_T temporalCounter_i1;         /* '<S1>/Chart' */
  boolean_T GyroMode_MODE;             /* '<S1>/GyroMode' */
  boolean_T GyroMode1_MODE;            /* '<S1>/GyroMode1' */
} D_Work_Ctrl;

/* External inputs (root inport signals with auto storage) */
typedef struct {
  boolean_T Active;                    /* '<Root>/Active' */
  uint32_T Mode;                       /* '<Root>/Mode' */
  boolean_T AckErrr;                   /* '<Root>/AckErrr' */
  real32_T Curr1;                      /* '<Root>/Curr1' */
  real32_T PWMRef1;                    /* '<Root>/PWMRef1' */
  real32_T PWMRef2;                    /* '<Root>/PWMRef2' */
  real32_T OmegaRef;                   /* '<Root>/OmegaRef' */
  real32_T OmegaZ;                     /* '<Root>/OmegaZ' */
  real32_T YawRef;                     /* '<Root>/YawRef' */
  real32_T MagY;                       /* '<Root>/MagY' */
  real32_T MagZ;                       /* '<Root>/MagZ' */
} ExternalInputs_Ctrl;

/* External outputs (root outports fed by signals with auto storage) */
typedef struct {
  boolean_T Kill;                      /* '<Root>/Kill' */
  uint32_T ActualState;                /* '<Root>/ActualState' */
  uint32_T ActualMode;                 /* '<Root>/ActualMode' */
  real32_T PWM1;                       /* '<Root>/PWM1' */
  real32_T PWM2;                       /* '<Root>/PWM2' */
  real32_T YawRad;                     /* '<Root>/YawRad' */
} ExternalOutputs_Ctrl;

/* Parameters (auto storage) */
struct Parameters_Ctrl_ {
  real32_T PWMs_Y0[2];                 /* Computed Parameter: PWMs_Y0
                                        * Referenced by: '<S4>/PWMs'
                                        */
  real32_T ProportionalGain_Gain;      /* Computed Parameter: ProportionalGain_Gain
                                        * Referenced by: '<S9>/Proportional Gain'
                                        */
  real32_T Integrator_gainval;         /* Computed Parameter: Integrator_gainval
                                        * Referenced by: '<S9>/Integrator'
                                        */
  real32_T Integrator_IC;              /* Computed Parameter: Integrator_IC
                                        * Referenced by: '<S9>/Integrator'
                                        */
  real32_T Saturation_UpperSat;        /* Computed Parameter: Saturation_UpperSat
                                        * Referenced by: '<S9>/Saturation'
                                        */
  real32_T Saturation_LowerSat;        /* Computed Parameter: Saturation_LowerSat
                                        * Referenced by: '<S9>/Saturation'
                                        */
  real32_T IntegralGain_Gain;          /* Computed Parameter: IntegralGain_Gain
                                        * Referenced by: '<S9>/Integral Gain'
                                        */
  real32_T Constant_Value;             /* Computed Parameter: Constant_Value
                                        * Referenced by: '<S9>/Constant'
                                        */
  real32_T PWMs_Y0_i[2];               /* Computed Parameter: PWMs_Y0_i
                                        * Referenced by: '<S5>/PWMs'
                                        */
  real32_T ProportionalGain_Gain_j;    /* Computed Parameter: ProportionalGain_Gain_j
                                        * Referenced by: '<S12>/Proportional Gain'
                                        */
  real32_T Saturation_UpperSat_k;      /* Computed Parameter: Saturation_UpperSat_k
                                        * Referenced by: '<S12>/Saturation'
                                        */
  real32_T Saturation_LowerSat_j;      /* Computed Parameter: Saturation_LowerSat_j
                                        * Referenced by: '<S12>/Saturation'
                                        */
  real32_T ProportionalGain_Gain_h;    /* Computed Parameter: ProportionalGain_Gain_h
                                        * Referenced by: '<S11>/Proportional Gain'
                                        */
  real32_T Integrator_gainval_f;       /* Computed Parameter: Integrator_gainval_f
                                        * Referenced by: '<S11>/Integrator'
                                        */
  real32_T Integrator_IC_m;            /* Computed Parameter: Integrator_IC_m
                                        * Referenced by: '<S11>/Integrator'
                                        */
  real32_T Saturation_UpperSat_h;      /* Computed Parameter: Saturation_UpperSat_h
                                        * Referenced by: '<S11>/Saturation'
                                        */
  real32_T Saturation_LowerSat_i;      /* Computed Parameter: Saturation_LowerSat_i
                                        * Referenced by: '<S11>/Saturation'
                                        */
  real32_T IntegralGain_Gain_d;        /* Computed Parameter: IntegralGain_Gain_d
                                        * Referenced by: '<S11>/Integral Gain'
                                        */
  real32_T Constant_Value_g;           /* Computed Parameter: Constant_Value_g
                                        * Referenced by: '<S11>/Constant'
                                        */
  real32_T PWMs_Y0_g[2];               /* Computed Parameter: PWMs_Y0_g
                                        * Referenced by: '<S6>/PWMs'
                                        */
  real32_T Constant1_Value;            /* Computed Parameter: Constant1_Value
                                        * Referenced by: '<S6>/Constant1'
                                        */
  real32_T Constant2_Value;            /* Computed Parameter: Constant2_Value
                                        * Referenced by: '<S6>/Constant2'
                                        */
  real32_T Bias_Bias;                  /* Computed Parameter: Bias_Bias
                                        * Referenced by: '<S2>/Bias'
                                        */
  real32_T Bias1_Bias;                 /* Computed Parameter: Bias1_Bias
                                        * Referenced by: '<S2>/Bias1'
                                        */
};

/* Real-time Model Data Structure */
struct RT_MODEL_Ctrl {
  const char_T * volatile errorStatus;

  /*
   * Timing:
   * The following substructure contains information regarding
   * the timing information for the model.
   */
  struct {
    uint32_T clockTick0;
    uint32_T clockTickH0;
  } Timing;
};

/* Class declaration for model Ctrl */
class CtrlModelClass {
  /* public data and function members */
 public:
  /* External inputs */
  ExternalInputs_Ctrl Ctrl_U;

  /* External outputs */
  ExternalOutputs_Ctrl Ctrl_Y;

  /* Model entry point functions */

  /* model initialize function */
  void initialize();

  /* model step function */
  void step();

  /* model terminate function */
  void terminate();

  /* Constructor */
  CtrlModelClass();

  /* Destructor */
  ~CtrlModelClass();

  /* Real-Time Model get method */
  RT_MODEL_Ctrl * getRTM() const;

  /* private data and function members */
 public:
  /* Tunable parameters */
  Parameters_Ctrl Ctrl_P;

  /* Block signals */
  BlockIO_Ctrl Ctrl_B;

  /* Block states */
  D_Work_Ctrl Ctrl_DWork;

  /* Real-Time Model */
  RT_MODEL_Ctrl Ctrl_M_;

  /* Real-Time Model pointer */
  RT_MODEL_Ctrl *Ctrl_M;

  /* private member function(s) for subsystem '<Root>' */
  void Ctrl_SetOutputs(real_T state);
  void Ctrl_SystemLogic(void);
  void Ctrl_TestOverCurrent(void);
};

/*-
 * The generated code includes comments that allow you to trace directly
 * back to the appropriate location in the model.  The basic format
 * is <system>/block_name, where system is the system number (uniquely
 * assigned by Simulink) and block_name is the name of the block.
 *
 * Note that this particular code originates from a subsystem build,
 * and has its own system numbers different from the parent model.
 * Refer to the system hierarchy for this subsystem below, and use the
 * MATLAB hilite_system command to trace the generated code back
 * to the parent model.  For example,
 *
 * hilite_system('MTCtrl/Ctrl')    - opens subsystem MTCtrl/Ctrl
 * hilite_system('MTCtrl/Ctrl/Kp') - opens and selects block Kp
 *
 * Here is the system hierarchy for this model
 *
 * '<Root>' : 'MTCtrl'
 * '<S1>'   : 'MTCtrl/Ctrl'
 * '<S2>'   : 'MTCtrl/Ctrl/Angleconverter'
 * '<S3>'   : 'MTCtrl/Ctrl/Chart'
 * '<S4>'   : 'MTCtrl/Ctrl/GyroMode'
 * '<S5>'   : 'MTCtrl/Ctrl/GyroMode1'
 * '<S6>'   : 'MTCtrl/Ctrl/Off'
 * '<S7>'   : 'MTCtrl/Ctrl/PWMMode'
 * '<S8>'   : 'MTCtrl/Ctrl/Angleconverter/MATLAB Function'
 * '<S9>'   : 'MTCtrl/Ctrl/GyroMode/Discrete PID Controller'
 * '<S10>'  : 'MTCtrl/Ctrl/GyroMode/Discrete PID Controller/Clamping circuit'
 * '<S11>'  : 'MTCtrl/Ctrl/GyroMode1/Discrete PID Controller'
 * '<S12>'  : 'MTCtrl/Ctrl/GyroMode1/Discrete PID Controller1'
 * '<S13>'  : 'MTCtrl/Ctrl/GyroMode1/Discrete PID Controller/Clamping circuit'
 */
#endif                                 /* RTW_HEADER_Ctrl_h_ */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
